from flask import Flask,redirect,url_for,request
import pymysql

# app = Flask(__name__)
app = Flask(__name__, static_folder='static')
db = pymysql.connect(host='localhost', user='root', password='123456', database='film')
cursor = db.cursor()  # 使用 cursor() 方法创建一个游标对象 cursor

@app.route('/filmname',methods=['POST'])
def film():
    print(request.form['filmname'])
    query_type = request.form.get('query_type', 'money')
    sql = "select " + query_type + " from piaofang where filmname = '%s'" % (request.form['filmname'])
    cursor.execute(sql)
    result = cursor.fetchone()
    field_name = {'time': '上映时间', 'count': '上映场次', 'money': '票房'}[query_type]
    return request.form['filmname'] + '的' + field_name + '是' + str(result[0])
# with open('piaofang.json' , 'r',encoding='utf-8') as file:
#     data = json.load(file)
# @app.route('/film/<film_name>')
# def age(film_name):
#     return redirect(url_for('static', filename=film_name+'.jpg'))
    # sql = "select money from piaofang where filmname = '%s'" % (film_name)
    # cursor.execute(sql)
    # result = cursor.fetchone()
    # return film_name + '的票房是' + result[0]

if __name__=='__main__':
    app.run(debug=True,host='127.0.0.1' , port=1234)